<?php
include "../../Lib/DBMySql.inc";
include "../../Lib/Common.php";
include "../../Lib/Lib.php";
include "../../Entities/docsObj.php";
include "../../DAL/docsDAL.php";
$mainDB = NewDB(DATABASE_HOST, DATABASE_NAME , DATABASE_USER, DATABASE_PASSWORD);

$doc = docsDAL::Load($mainDB, $id, $errorPage);

if ($doc!=null)
{
	//print_r($doc);
	//echo 235;
	//exit;
	if (file_exists(WS_ROOT.$doc->uploadedDir.$doc->name))
	{
		header("Content-Disposition: attachment; filename=\"".$doc->originalName."\"");
		header("Content-Type: ".$doc->type);
		header("Pragma: no-cache");
		header("Expires: 0");
		
		$filename = WS_ROOT.$doc->uploadedDir.$doc->name;
		$handle = fopen($filename, "r");
		$fileContent = fread($handle, filesize($filename));
		fclose($handle);
		
		echo $fileContent;
	}
}
?>